<!--
 * @Author: Lin Ming
 * @Date: 2021-02-23 14:23:24
 * @LastEditors: Lin Ming
 * @LastEditTime: 2021-02-23 17:58:41
 * @FilePath: \vue-zheye\src\components\ColumnList.vue
-->
<template>
  <div class="lm-column-list">
    <div class="row">
      <div class="col-4 mb-4" v-for="item in columnList" :key="item.id">
        <div class="card h-100 shadow-sm">
          <div class="card-body text-center">
            <img :src="item.avatar" :alt="item.title" class="card-img-top rounded-circle border border-light w-25 my-3">
            <h5 class="card-title">{{item.title}}</h5>
            <p class="card-text text-left">{{item.description}}</p>
            <a href="#" class="btn btn-outline-primary">进入专栏</a>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, PropType, computed } from 'vue'
export interface ColumnProps {
  id: number;
  title: string;
  avatar?: string;
  description: string;
}
export default defineComponent({
  name: 'ColumnList',
  props: {
    list: {
      type: Array as PropType<ColumnProps[]>,
      required: true
    }
  },
  setup (props) {
    const columnList = computed(() => {
      return props.list.map(item => {
        if (!item.avatar) {
          console.log(333)
          item.avatar = require('../assets/err.jpg')
        }
        return item
      })
    })
    console.log(columnList)
    return {
      columnList
    }
  }
})
</script>
